package org.example.Day5.DouDiZhu;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

public class Room {
    private List<Card> allCards = new ArrayList<>();
    public Room(){
        //做出54张牌 存入allCards
        //点数：个数确定，类型确定
        String[] numbers = {
                "3","4","5","6","7","8","9","10","J","Q","K","A","2"
        };
        String[] colors = {
                "♠", "♥", "♣", "♦"
        };
        int size = 0;
        for (String number:numbers){
            size++;
            for(String color:colors){
                Card c = new Card(number,color,size);
                allCards.add(c);

            }
        }
        Card c1 = new Card("", "小丑" , ++size);
        Card c2 = new Card("", "大丑" , ++size);
        Collections.addAll(allCards, c1, c2);
        System.out.println("新牌：" + allCards);
    }
    public void start(){
        //洗牌
        Collections.shuffle(allCards);//打乱元素顺序
        System.out.println("洗牌后:"+allCards);
        //定义三个收牌人
        List<Card> zhangwentao = new ArrayList<>();
        List<Card> wanghaitao = new ArrayList<>();
        List<Card> chenleyang = new ArrayList<>();
        for(int i = 0; i < allCards.size();i++){
            Card c = allCards.get(i);
            if(i%3 == 0){
                zhangwentao.add(c);
            }else if(i%3==1){
                wanghaitao.add(c);

            }else if(i%3== 2){
                chenleyang.add(c);
            }

        }
        //排序
        sortCards(zhangwentao);
        sortCards(wanghaitao);
        sortCards(chenleyang);

        System.out.println("大宝：" + zhangwentao);
        System.out.println("小宝：" + wanghaitao);
        System.out.println("咸咸：" + chenleyang);
        List<Card> lastThreeCards = allCards.subList(allCards.size() - 3, allCards.size());

        System.out.println("底牌：" + lastThreeCards);
        wanghaitao.addAll(lastThreeCards);
        sortCards(wanghaitao);
        System.out.println("小宝抢到地主后：" + wanghaitao);
    }
    public void sortCards(List<Card> cards){
        Collections.sort(cards, new Comparator<Card>() {
            @Override

            public int compare(Card o1, Card o2) {

                // return o1.getSize() - o2.getSize(); // 升序排序

                return o2.getSize() - o1.getSize(); // 降序排序
            }
        });
    }
}